/**
 * Created by Administrator on 2018/6/9.
 */

function editEmployeeInit($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http) {
    $scope.baseUser = {};
    $scope.userOperate = function () {
        //console.log($scope.sdata);
        // $.post('/userOperate',JSON.stringify($scope.baseUser),function(d){
        //     console.log(d);
        // })
        if(certusValidateNotnull()){
            CertusJsonAjax.ajax("userOperate", $scope.baseUser, function (response) {
                if ("success" == eval(response.data)) {
                    // var index=parent.layer.getFrameIndex(window.name);
                    // parent.layer.close(index);
                    history.back();
                } else if ("logout" == response.data) {
                    certusUtils1.logout();
                }
            })
        }

    };

    var picker2 = $('#datetime').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if (result && !angular.isUndefined(result)) {
            $scope.baseUser.birthday = result;
            $scope.$apply();
        }
    })

    var picker3 = $('#datetime1').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if (result && !angular.isUndefined(result)) {
            $scope.baseUser.enrollTime = result;
            $scope.$apply();
        }
    })

    CertusFormAjax.ajax("companyList",{},function(res){
        $scope.companySelect = eval("("+res.data+")");
        CertusFormAjax.ajax("deptedList", {}, function (result) {

            //初始化 公司 select 选择框 数据
            $scope.departmentSelect = eval("("+result.data+")")

            //性别 选择框
            //初始化 select 选择框 数据
            $scope.sexSelect = [
                {sexName: '男', sex: "1"},
                {sexName: '女', sex: "0"}
            ];

            $scope.marriageSelect = [
                {marriageName: "未婚", isMarriage: "0"},
                {marriageName: "已婚", isMarriage: "1"},
                {marriageName: "已婚已孕", isMarriage: "2"}
            ]
            $scope.onPostSelect = [
                {onPost: "1", onPostName: "在职"},
                {onPost: "0", onPostName: "离职"}
            ]
        });
    })





    //只保留 数字
    $scope.clearNum = function (obj, attr) {
        $scope.baseUser[attr] = $scope.baseUser[attr].replace(/\D/g, "");
    }

    $scope.changeDept = function(a,b,c){
        CertusFormAjax.ajax("deptedList", {companyCode:a}, function (res) {
            $scope.departmentSelect =eval("("+res.data+")");

        })
    }
}
